from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-03-13 14:02:17.510272
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 13, Mar, 2022
Time: 14:02:22
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.5049
Nobs: 594.000 HQIC: -48.9107
Log likelihood: 7107.71 FPE: 4.42544e-22
AIC: -49.1695 Det(Omega_mle): 3.80805e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.349809 0.067047 5.217 0.000
L1.Burgenland 0.108453 0.040838 2.656 0.008
L1.Kärnten -0.110604 0.021335 -5.184 0.000
L1.Niederösterreich 0.192542 0.085317 2.257 0.024
L1.Oberösterreich 0.122812 0.084166 1.459 0.145
L1.Salzburg 0.257992 0.043288 5.960 0.000
L1.Steiermark 0.036171 0.057127 0.633 0.527
L1.Tirol 0.101697 0.046136 2.204 0.028
L1.Vorarlberg -0.067908 0.040703 -1.668 0.095
L1.Wien 0.016371 0.074927 0.218 0.827
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.053840 0.144205 0.373 0.709
L1.Burgenland -0.037821 0.087833 -0.431 0.667
L1.Kärnten 0.041959 0.045888 0.914 0.361
L1.Niederösterreich -0.204694 0.183499 -1.116 0.265
L1.Oberösterreich 0.455977 0.181023 2.519 0.012
L1.Salzburg 0.283407 0.093104 3.044 0.002
L1.Steiermark 0.112873 0.122869 0.919 0.358
L1.Tirol 0.305295 0.099229 3.077 0.002
L1.Vorarlberg 0.026448 0.087543 0.302 0.763
L1.Wien -0.028241 0.161152 -0.175 0.861
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197925 0.034255 5.778 0.000
L1.Burgenland 0.089080 0.020865 4.269 0.000
L1.Kärnten -0.007099 0.010901 -0.651 0.515
L1.Niederösterreich 0.241576 0.043590 5.542 0.000
L1.Oberösterreich 0.159355 0.043002 3.706 0.000
L1.Salzburg 0.040223 0.022117 1.819 0.069
L1.Steiermark 0.027059 0.029187 0.927 0.354
L1.Tirol 0.081343 0.023572 3.451 0.001
L1.Vorarlberg 0.054033 0.020796 2.598 0.009
L1.Wien 0.118705 0.038281 3.101 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.118429 0.034250 3.458 0.001
L1.Burgenland 0.043099 0.020861 2.066 0.039
L1.Kärnten -0.012954 0.010899 -1.189 0.235
L1.Niederösterreich 0.172002 0.043583 3.947 0.000
L1.Oberösterreich 0.335748 0.042995 7.809 0.000
L1.Salzburg 0.099965 0.022113 4.521 0.000
L1.Steiermark 0.111363 0.029182 3.816 0.000
L1.Tirol 0.089322 0.023568 3.790 0.000
L1.Vorarlberg 0.060400 0.020792 2.905 0.004
L1.Wien -0.017610 0.038275 -0.460 0.645
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.126420 0.064318 1.966 0.049
L1.Burgenland -0.044395 0.039175 -1.133 0.257
L1.Kärnten -0.045332 0.020467 -2.215 0.027
L1.Niederösterreich 0.135323 0.081844 1.653 0.098
L1.Oberösterreich 0.160203 0.080739 1.984 0.047
L1.Salzburg 0.285320 0.041526 6.871 0.000
L1.Steiermark 0.058286 0.054801 1.064 0.288
L1.Tirol 0.157951 0.044258 3.569 0.000
L1.Vorarlberg 0.097135 0.039046 2.488 0.013
L1.Wien 0.072243 0.071877 1.005 0.315
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.076948 0.050211 1.532 0.125
L1.Burgenland 0.025818 0.030583 0.844 0.399
L1.Kärnten 0.053326 0.015978 3.338 0.001
L1.Niederösterreich 0.190206 0.063892 2.977 0.003
L1.Oberösterreich 0.331063 0.063030 5.252 0.000
L1.Salzburg 0.034981 0.032418 1.079 0.281
L1.Steiermark 0.008046 0.042782 0.188 0.851
L1.Tirol 0.118635 0.034551 3.434 0.001
L1.Vorarlberg 0.065776 0.030482 2.158 0.031
L1.Wien 0.097299 0.056112 1.734 0.083
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.173708 0.060529 2.870 0.004
L1.Burgenland 0.005056 0.036867 0.137 0.891
L1.Kärnten -0.065844 0.019261 -3.419 0.001
L1.Niederösterreich -0.107944 0.077022 -1.401 0.161
L1.Oberösterreich 0.207154 0.075983 2.726 0.006
L1.Salzburg 0.054817 0.039080 1.403 0.161
L1.Steiermark 0.247007 0.051573 4.789 0.000
L1.Tirol 0.500385 0.041651 12.014 0.000
L1.Vorarlberg 0.064095 0.036745 1.744 0.081
L1.Wien -0.075316 0.067642 -1.113 0.266
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160862 0.067157 2.395 0.017
L1.Burgenland -0.002023 0.040905 -0.049 0.961
L1.Kärnten 0.062950 0.021370 2.946 0.003
L1.Niederösterreich 0.166475 0.085457 1.948 0.051
L1.Oberösterreich -0.056315 0.084304 -0.668 0.504
L1.Salzburg 0.208667 0.043359 4.813 0.000
L1.Steiermark 0.138573 0.057221 2.422 0.015
L1.Tirol 0.055607 0.046212 1.203 0.229
L1.Vorarlberg 0.146866 0.040769 3.602 0.000
L1.Wien 0.121569 0.075050 1.620 0.105
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.389975 0.039495 9.874 0.000
L1.Burgenland -0.003268 0.024056 -0.136 0.892
L1.Kärnten -0.020864 0.012568 -1.660 0.097
L1.Niederösterreich 0.202812 0.050257 4.035 0.000
L1.Oberösterreich 0.228393 0.049579 4.607 0.000
L1.Salzburg 0.037038 0.025500 1.453 0.146
L1.Steiermark -0.015551 0.033652 -0.462 0.644
L1.Tirol 0.089569 0.027177 3.296 0.001
L1.Vorarlberg 0.050837 0.023976 2.120 0.034
L1.Wien 0.043963 0.044137 0.996 0.319
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036812 0.104453 0.167734 0.138235 0.096514 0.080382 0.032376 0.209846
Kärnten 0.036812 1.000000 -0.027293 0.131179 0.048528 0.084741 0.443734 -0.067197 0.089242
Niederösterreich 0.104453 -0.027293 1.000000 0.312250 0.118763 0.272126 0.065485 0.152293 0.291037
Oberösterreich 0.167734 0.131179 0.312250 1.000000 0.212194 0.294822 0.166313 0.136375 0.237722
Salzburg 0.138235 0.048528 0.118763 0.212194 1.000000 0.122473 0.091189 0.104722 0.123744
Steiermark 0.096514 0.084741 0.272126 0.294822 0.122473 1.000000 0.133216 0.106264 0.035298
Tirol 0.080382 0.443734 0.065485 0.166313 0.091189 0.133216 1.000000 0.063245 0.150911
Vorarlberg 0.032376 -0.067197 0.152293 0.136375 0.104722 0.106264 0.063245 1.000000 -0.004400
Wien 0.209846 0.089242 0.291037 0.237722 0.123744 0.035298 0.150911 -0.004400 1.000000